﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Write.API.Applications.Login;
using MediatR;

namespace MangoMes.Write.API.Applications.process
{
    public class processCreateHandler:IRequestHandler<processCreateCommond, ResultsDTO>
    {

        private readonly IBateRepository<processk> _process;


        private readonly Logincommonality _Logincommonality;

        public processCreateHandler(IBateRepository<processk> process, Logincommonality logincommonality)
        {
            _process = process;
            _Logincommonality = logincommonality;
        }

        public async Task<ResultsDTO> Handle(processCreateCommond request, CancellationToken cancellationToken)
        {
            try
            {
                var list = new ResultsDTO() { Code = 0 };

                var per = new processk()
                {
                    DescriptionToreMark = request.DescriptionToreMark,
                    isEnable = request.isEnable,
                    ProcedureCode = request.ProcedureCode
                   ,
                    processid = request.processid
                  ,
                    ProcessInstructions = request.ProcessInstructions
                  ,
                    ProcessName = request.ProcessName
                };

                DapperHelper dapperHelper = new DapperHelper();
                var str = "insert processk values(@processid,@ProcedureCode,@ProcessName,@isEnable,@ProcessInstructions,@DescriptionToreMark)";


                var getdata = await _process.Add(str, per, dapperHelper.MangoMesWrite);

                if (getdata != null)
                {


                    var OperatorName = "123";
                    var OperatorTime = DateTime.Now.ToString();
                    var PerformOperation = "工序添加";
                    _Logincommonality.Loginaddget(OperatorName, OperatorTime, PerformOperation);






                    list.Code = 1;
                    list.Message = "工序添加成功";
                }

                return list;
            }
            catch (Exception)
            {

                throw;
            }
           

        }
    }
}
